package com.umpay.sp.saas.action.batchNet;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.apache.poi.hssf.usermodel.HSSFSheet;

import com.umpay.operation.common.ReqMessage;
import com.umpay.operation.common.ResMessage;
import com.umpay.operation.model.saas.StoreBatch;
import com.umpay.operation.model.saas.StoreBatchDetail;
import com.umpay.sp.common.LoggerManager;
import com.umpay.sp.saas.util.DataEntryUtil;
import com.umpay.sp.saas.util.DesIDUtil;
import com.umpay.sp.saas.util.ReqMessageUtil;
import com.umpay.sp.saas.util.SaasPropertyUtil;
import com.umpay.sp.saas.util.ValidateUtil;
import com.umpay.sp.web.util.DateUtil;

public class BatchNetThread extends Thread {
	
	private static Logger logger = LoggerManager.getBatchLogger();

	private HSSFSheet sheet;//Excel文件
	private String batchNo;//批次号
	
	private String invalidInfo = "";//无效信息
	private int invalidState = 0;//无效状态
	
	/**
	 * 初始化数据
	 * @param sheet
	 */
	public BatchNetThread(HSSFSheet sheet, String batchNo){
		this.sheet = sheet;
		this.batchNo = batchNo;
	}
	
	/**
	 * 开始执行线程
	 */
	public synchronized void run(){
		logger.info("【线程开始处理Excel数据】");
		for (int i = 1; i <= sheet.getLastRowNum(); i++) {
			String errInfo = "";//错误信息
			int errState = 0;//错误状态
			String defultStore = "0";//默认店铺：0默认店铺；1非默认店铺
			String merId = "";//主商户号
			String seqNum = String.valueOf(sheet.getRow(i).getCell(0)).trim();//序列号
			
			String agentId = String.valueOf(sheet.getRow(i).getCell(1)).trim();//代理商编号
			Map<String, String> map1 = ValidateUtil.agentId(agentId);
			if (!map1.get("retCode").equals("0000")) {
				errInfo = errInfo + map1.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(agentId)) {
					agentId = "";
				}else if (agentId.length() > 10) {
					agentId = "";
				}
			}
			
			String storeType = String.valueOf(sheet.getRow(i).getCell(2)).trim();//商户类型：0小微；1个体（企业）
			if (storeType.contains("个体")) {
				storeType = "1";
			}else {
				storeType = "0";
			}
			
			String payeeName = String.valueOf(sheet.getRow(i).getCell(3)).trim();//收款人姓名
			String payeeInidcard = String.valueOf(sheet.getRow(i).getCell(4)).trim();//收款人身份证号码
			String payeeInidcardValid = String.valueOf(sheet.getRow(i).getCell(5)).trim();//收款人身份证证件有效期
			if (payeeInidcardValid.contains("/")) {
				payeeInidcardValid = payeeInidcardValid.replaceAll("/", "-");
			}
			String payeeMobileId = String.valueOf(sheet.getRow(i).getCell(6)).trim();//收款人收款人手机号
			Map<String, String> map6 = ValidateUtil.identityInfo(payeeName, payeeInidcard, payeeInidcardValid, payeeMobileId);
			if (!map6.get("retCode").equals("0000")) {
				errInfo = errInfo + map6.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(payeeName)) {
					payeeName = "";
				}else if (payeeName.length() > 32) {
					payeeName = "";
				}
				if ("null".equals(payeeInidcard)) {
					payeeInidcard = "";
				}else if (payeeInidcard.length() > 100) {
					payeeInidcard = "";
				}
				if ("null".equals(payeeInidcardValid)) {
					payeeInidcardValid = "";
				}else if (payeeInidcardValid.length() > 16) {
					payeeInidcardValid = "";
				}
				if ("null".equals(payeeMobileId)) {
					payeeMobileId = "";
				}else if (payeeMobileId.length() > 16) {
					payeeMobileId = "";
				}
				
			}else {
				defultStore = map6.get("defultStore");
				if (StringUtils.isNotBlank(map6.get("merId"))) {
					merId = map6.get("merId");
				}
			}
			
			String storeShortName = String.valueOf(sheet.getRow(i).getCell(7)).trim();//商户简称（用于前端显示）
			Map<String, String> map7 = ValidateUtil.storeShortName(storeShortName);
			if (!map7.get("retCode").equals("0000")) {
				errInfo = errInfo + map7.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeShortName)) {
					storeShortName = "";
				}else if (storeShortName.length() > 16) {
					storeShortName = "";
				}
			}
			
			String storeCategory = String.valueOf(sheet.getRow(i).getCell(8)).trim();//商户类别（经营类目）
			Map<String, String> map8 = ValidateUtil.storeCategory(storeCategory);
			if (!map8.get("retCode").equals("0000")) {
				errInfo = errInfo + map8.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeCategory)) {
					storeCategory = "";
				}else if(storeCategory.length() > 32){
					storeCategory = "";
				}
			}
			
			String phone = String.valueOf(sheet.getRow(i).getCell(9)).trim();//客服电话
			Map<String, String> map9 = ValidateUtil.phone(phone);
			if (!map9.get("retCode").equals("0000")) {
				errInfo = errInfo + map9.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(phone)) {
					phone = "";
				}else if (phone.length() > 16) {
					phone = "";
				}
			}
			
			String storeAddrProv = String.valueOf(sheet.getRow(i).getCell(10)).trim();//省
			Map<String, String>	map10 = ValidateUtil.storeAddrProv(storeAddrProv);
			if (!map10.get("retCode").equals("0000")) {
				errInfo = errInfo + map10.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeAddrProv)) {
					storeAddrProv = "";
				}else if (storeAddrProv.length() > 10) {
					storeAddrProv = "";
				}
			}
			
			String storeAddrCity = String.valueOf(sheet.getRow(i).getCell(11)).trim();//市
			Map<String, String> map11 = ValidateUtil.storeAddrCity(storeAddrCity);
			if (!map11.get("retCode").equals("0000")) {
				errInfo = errInfo + map11.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeAddrCity)) {
					storeAddrCity = "";
				}else if (storeAddrCity.length() > 10) {
					storeAddrCity = "";
				}
			}
			
			String storeAddrArea = String.valueOf(sheet.getRow(i).getCell(12)).trim();//区
			Map<String, String> map12 = ValidateUtil.storeAddrArea(storeAddrArea);
			if (!map12.get("retCode").equals("0000")) {
				errInfo = errInfo + map12.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeAddrArea)) {
					storeAddrArea = "";
				}else if (storeAddrArea.length() > 10) {
					storeAddrArea = "";
				}
			}
			
			String storeFullAddr = String.valueOf(sheet.getRow(i).getCell(13)).trim();//详细地址
			Map<String, String> map13 = ValidateUtil.storeFullAddress(storeFullAddr);
			if (!map13.get("retCode").equals("0000")) {
				errInfo = errInfo + map13.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(storeFullAddr)) {
					storeFullAddr = "";
				}else if (storeFullAddr.length() > 128) {
					storeFullAddr = "";
				}
			}
			
			String bankAccount = String.valueOf(sheet.getRow(i).getCell(23)).trim();//银行账号
			String prestorePhone = String.valueOf(sheet.getRow(i).getCell(24)).trim();//银行预留手机号
			String payeeName2 = String.valueOf(sheet.getRow(i).getCell(3)).trim();//收款人姓名
			String payeeInidcard2 = String.valueOf(sheet.getRow(i).getCell(4)).trim();//收款人身份证号码
			Map<String, String> map23 = ValidateUtil.bankAccount(payeeName2, payeeInidcard2, bankAccount, prestorePhone);
			if (!map23.get("retCode").equals("0000")) {
				errInfo = errInfo + map23.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(bankAccount)) {
					bankAccount = "";
				}else if (bankAccount.length() > 128) {
					bankAccount = "";
				}
				if ("null".equals(prestorePhone)) {
					prestorePhone = "";
				}else if (prestorePhone.length() > 16) {
					prestorePhone = "";
				}
			}
			
			String wecatRates = String.valueOf(sheet.getRow(i).getCell(28)).trim();//立马付微信费率
			String alipayRates = String.valueOf(sheet.getRow(i).getCell(29)).trim();//立马付支付宝费率
			String agentId2 = String.valueOf(sheet.getRow(i).getCell(1)).trim();//代理商编号
			Map<String, String> map28 = null;
			try {
				map28 = ValidateUtil.rate(agentId2, wecatRates, alipayRates);
			} catch (Exception e) {
				//下面判断空，此处不再做任何操作
			}
			if (null == map28) {
				errInfo = errInfo + "费率校验失败请重试" + " | ";
				errState = 1;
			}else if(!map28.get("retCode").equals("0000")) {
				errInfo = errInfo + map28.get("retMsg") + " | ";
				errState = 1;
			}
			if ("null".equals(wecatRates)) {
				wecatRates = "";
			}else if (wecatRates.length() > 5) {
				wecatRates = "";
			}
			if ("null".equals(alipayRates)) {
				alipayRates = "";
			}else if (alipayRates.length() > 5) {
				alipayRates = "";
			}
			
			String email = String.valueOf(sheet.getRow(i).getCell(22)).trim();//邮箱
			Map<String, String> map22 = ValidateUtil.email(email);
			if (!map22.get("retCode").equals("0000")) {
				errInfo = errInfo + map22.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(email)) {
					email = "";
				}else if (email.length() > 60) {
					email = "";
				}
			}
			
			String labelOne = String.valueOf(sheet.getRow(i).getCell(25)).trim();//标签一
			Map<String, String> map25 = ValidateUtil.labelOne(labelOne);
			if (!map25.get("retCode").equals("0000")) {
				errInfo = errInfo + map25.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(labelOne)) {
					labelOne = "";
				}else if (labelOne.length() > 32) {
					labelOne = "";
				}
			}
			
			String labelTwo = String.valueOf(sheet.getRow(i).getCell(26)).trim();//标签二
			Map<String, String> map26 = ValidateUtil.labelTwo(labelTwo);
			if (!map26.get("retCode").equals("0000")) {
				errInfo = errInfo + map26.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(labelTwo)) {
					labelTwo = "";
				}else if (labelTwo.length() > 32) {
					labelTwo = "";
				}
			}
			
			String salesmanId = String.valueOf(sheet.getRow(i).getCell(27)).trim();//业务员
			String agentId3 = String.valueOf(sheet.getRow(i).getCell(1)).trim();//代理商编号
			if (StringUtils.isBlank(salesmanId) || "null".equals(salesmanId)) {
				salesmanId = "admin";
			}
			Map<String, String> map27 = ValidateUtil.salesmanId(agentId3, salesmanId);
			if (!map27.get("retCode").equals("0000")) {
				errInfo = errInfo + map27.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(salesmanId)) {
					salesmanId = "admin";
				}else if(salesmanId.length() > 16){
					salesmanId = "";
				}
			}
			
			String codeOne = String.valueOf(sheet.getRow(i).getCell(30)).trim();//固码1
			Map<String, String> map30 = ValidateUtil.codeOne(codeOne);
			if (!map30.get("retCode").equals("0000")) {
				errInfo = errInfo + map30.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(codeOne)) {
					codeOne = "";
				}else if (codeOne.length() > 8) {
					codeOne = "";
				}
			}
			
			String codeTwo = String.valueOf(sheet.getRow(i).getCell(31)).trim();//固码2
			Map<String, String> map31 = ValidateUtil.codeTwo(codeTwo);
			if (!map31.get("retCode").equals("0000")) {
				errInfo = errInfo + map31.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(codeTwo)) {
					codeTwo = "";
				}else if (codeTwo.length() > 8) {
					codeTwo = "";
				}
			}
			
			String codeThree = String.valueOf(sheet.getRow(i).getCell(32)).trim();//固码3
			Map<String, String> map32 = ValidateUtil.codeThree(codeThree);
			if (!map32.get("retCode").equals("0000")) {
				errInfo = errInfo + map32.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(codeThree)) {
					codeThree = "";
				}else if (codeThree.length() > 8) {
					codeThree = "";
				}
			}
			
			String codeFour = String.valueOf(sheet.getRow(i).getCell(33)).trim();//固码4
			Map<String, String> map33 = ValidateUtil.codeFour(codeFour);
			if (!map33.get("retCode").equals("0000")) {
				errInfo = errInfo + map33.get("retMsg") + " | ";
				errState = 1;
				if ("null".equals(codeFour)) {
					codeFour = "";
				}else if (codeFour.length() > 8) {
					codeFour = "";
				}
			}
			
			String licenseNo = "";
			String storeFullName = "";
			String registerDate = "";
			String mainBusiness = "";
			String categoryManName = "";
			String categoryManCardno = "";
			String categoryInidcardValid = "";
			String rgstaddress = "";
			if (storeType.equals("1")) {//如果是1个体（企业），才有这些
				licenseNo = String.valueOf(sheet.getRow(i).getCell(14)).trim();//营业执照号
				Map<String, String> map14 = ValidateUtil.licenseNo(licenseNo);
				if (!map14.get("retCode").equals("0000")) {
					errInfo = errInfo + map14.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(licenseNo)) {
						licenseNo = "";
					}else if (licenseNo.length() > 32) {
						licenseNo = "";
					}
				}
				
				storeFullName = String.valueOf(sheet.getRow(i).getCell(15)).trim();//营业执照名称
				Map<String, String> map15 = ValidateUtil.storeName(storeFullName);
				if (!map15.get("retCode").equals("0000")) {
					errInfo = errInfo + map15.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(storeFullName)) {
						storeFullName = "";
					}else if (storeFullName.length() > 64) {
						storeFullName = "";
					}
				}
				
				registerDate = String.valueOf(sheet.getRow(i).getCell(16)).trim();//营业执照注册日期
				if (registerDate.contains("/")) {
					registerDate = registerDate.replaceAll("/", "-");
				}
				Map<String, String> map16 = ValidateUtil.registerDate(registerDate);
				if (!map16.get("retCode").equals("0000")) {
					errInfo = errInfo + map16.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(registerDate)) {
						registerDate = "";
					}else if (registerDate.length() > 16) {
						registerDate = "";
					}
				}
				
				mainBusiness = String.valueOf(sheet.getRow(i).getCell(17)).trim();//主营业务
				Map<String, String> map17 = ValidateUtil.storeKind(mainBusiness);
				if (!map17.get("retCode").equals("0000")) {
					errInfo = errInfo + map17.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(mainBusiness)) {
						mainBusiness = "";
					}else if (mainBusiness.length() > 128) {
						mainBusiness = "";
					}
				}
				
				categoryManName = String.valueOf(sheet.getRow(i).getCell(18)).trim();//法人姓名
				Map<String, String> map18 = ValidateUtil.storeMan(categoryManName);
				if (!map18.get("retCode").equals("0000")) {
					errInfo = errInfo + map18.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(categoryManName)) {
						categoryManName = "";
					}else if (categoryManName.length() > 32) {
						categoryManName = "";
					}
				}
				
				String categoryManName2 = String.valueOf(sheet.getRow(i).getCell(18)).trim();//法人姓名
				categoryManCardno = String.valueOf(sheet.getRow(i).getCell(19)).trim();//法人证件号
				categoryInidcardValid = String.valueOf(sheet.getRow(i).getCell(20)).trim();//法人证件号有效期
				if (categoryInidcardValid.contains("/")) {
					categoryInidcardValid = categoryInidcardValid.replaceAll("/", "-");
				}
				Map<String, String> map19 = ValidateUtil.storeManIdentity(categoryManName2, categoryManCardno, categoryInidcardValid);
				if (!map19.get("retCode").equals("0000")) {
					errInfo = errInfo + map19.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(categoryManCardno)) {
						categoryManCardno = "";
					}else if (categoryManCardno.length() > 128) {
						categoryManCardno = "";
					}
					if ("null".equals(categoryInidcardValid)) {
						categoryInidcardValid = "";
					}else if (categoryInidcardValid.length() > 16) {
						categoryInidcardValid = "";
					}
				}
				
				rgstaddress = String.valueOf(sheet.getRow(i).getCell(21)).trim();//商户注册详细地址
				Map<String, String> map21 = ValidateUtil.registerAddress(rgstaddress);
				if (!map21.get("retCode").equals("0000")) {
					errInfo = errInfo + map21.get("retMsg") + " | ";
					errState = 1;
					if ("null".equals(rgstaddress)) {
						rgstaddress = "";
					}else if (rgstaddress.length() > 64) {
						rgstaddress = "";
					}
				}
				
			}
			
			//~~~~~~~~~~~~~~~~~~~~~~~~~保存批次详情~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage req = ReqMessageUtil.makeOpReq();
			ResMessage res = null;
			String uuid = UUID.randomUUID().toString();//批次明细ID
			req.put("batchNo",batchNo);//批次ID
			req.put("uuid",uuid);//批次明细ID
			req.put("agentId","null".equals(agentId) ? "" : agentId);//代理商编号
			req.put("salesmanId","null".equals(salesmanId) ? "admin" : salesmanId );//业务员编号
			req.put("payeeName","null".equals(payeeName) ? "" : payeeName);//收款人姓名
			req.put("payeeInidcard","null".equals(payeeInidcard) ? "" :DesIDUtil.encID(payeeInidcard));//收款人身份证号（加密）
			req.put("payeeInidcardValid","null".equals(payeeInidcardValid) ? "" : payeeInidcardValid);//收款人身份证有效期
			req.put("payeeMobileId","null".equals(payeeMobileId) ? "" : payeeMobileId);//收款人手机号码
			req.put("storeShortName","null".equals(storeShortName) ? "" : storeShortName);//商户简称
			req.put("storeCategory","null".equals(storeCategory) ? "" : storeCategory.replaceAll("/", "&"));//商户类别
			req.put("phone","null".equals(phone) ? "" : phone);//客服电话
			req.put("storeAddrProv","null".equals(storeAddrProv) ? "" : storeAddrProv);//商户地址/省
			req.put("storeAddrCity","null".equals(storeAddrCity) ? "" : storeAddrCity);//商户地址/市
			req.put("storeAddrArea","null".equals(storeAddrArea) ? "" : storeAddrArea);//商户地址/区
			req.put("storeFullAddr","null".equals(storeFullAddr) ? "" : storeFullAddr);//商户详细地址
			req.put("storeType","null".equals(storeType) ? "" : storeType);//商户类型
			req.put("registerProcsState","06");//店铺处理状态
			req.put("licenseNo","null".equals(licenseNo) ? "" : licenseNo);//个体商户营业执照号
			req.put("storeFullName","null".equals(storeFullName) ? "" : storeFullName);//个体商户全称
			req.put("registerDate","null".equals(registerDate) ? "" : registerDate);//注册日期
			req.put("mainBusiness","null".equals(mainBusiness) ? "" : mainBusiness);//主营业务
			req.put("rgstaddress","null".equals(rgstaddress) ? "" : rgstaddress);//注册地址
			req.put("categoryManName","null".equals(categoryManName) ? "" : categoryManName);//经营者姓名
			req.put("categoryManCardno","null".equals(categoryManCardno) ? "" : DesIDUtil.encID(categoryManCardno));//经营者身份证号码(加密)
			req.put("categoryInidcardValid","null".equals(categoryInidcardValid) ? "" : categoryInidcardValid);//经营者身份证有效期
			req.put("labelOne","null".equals(labelOne) ? "" : labelOne);//标签一
			req.put("labelTwo","null".equals(labelTwo) ? "" : labelTwo);//标签二
			req.put("bankAccount","null".equals(bankAccount) ? "" : DesIDUtil.encID(bankAccount));//银行账号
			req.put("prestorePhone","null".equals(prestorePhone) ? "" : prestorePhone);//银行预留手机号
			req.put("wecatRates",wecatRates.equals("") || "null".equals(wecatRates) ? "0" : (new BigDecimal(wecatRates).multiply(new BigDecimal(1000))).intValue());//立马付微信费率（%）
			req.put("alipayRates",alipayRates.equals("") || "null".equals(alipayRates) ? "0" : (new BigDecimal(alipayRates).multiply(new BigDecimal(1000))).intValue());//立马付支付宝费率（%）
			req.put("codeOne","null".equals(codeOne) ? "" : codeOne);//固码1
			req.put("codeTwo","null".equals(codeTwo) ? "" : codeTwo);//固码2
			req.put("codeThree","null".equals(codeThree) ? "" : codeThree);//固码3
			req.put("codeFour","null".equals(codeFour) ? "" : codeFour);//固码4
			req.put("delFlag","0");//是否删除
			req.put("failReason",errInfo);//失败原因
			req.put("email","null".equals(email) ? "" : email);//邮箱
			try {
				res = DataEntryUtil.saveBatchDetail(req);
			} catch (Exception e) {
				invalidInfo = invalidInfo + seqNum + "、";
				invalidState ++;
			}
			if (!res.getRetCode().equals("0000")) {
				invalidInfo = invalidInfo + seqNum + "、";
				invalidState ++;
				continue;
			}
			if (errState > 0) {
				continue;
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~创建店铺~~~~~~~~~~~~~~~~~~~~~~~~~
			req.put("merId",merId);//主商户号
			req.put("defultStore",defultStore);//默认店铺
			req.put("registerProcsState","03");//店铺处理状态
			req.put("type","1");//入网方式：0单个；1批量
			req.put("isDel","0");//是否删除
			try {
				res = DataEntryUtil.createStore(req);
			} catch (Exception e) {
				errInfo = "服务器异常，请稍后再试";
				errState = 1;
			}
			
			//~~~~~~~~~~~~~~~~~~~~~~~~~先查询批次详情，再更新~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage reqDetail = ReqMessageUtil.makeOpReq();
			ResMessage resDetail = null;
			reqDetail.put("batchNo",batchNo);//批次号
			reqDetail.put("uuid",uuid);
			try {
				resDetail = DataEntryUtil.getBatchDetailByPri(reqDetail);
			} catch (Exception e) {
				logger.error("【根据主键查询批次详情信息】异常", e);
			}
			if(resDetail.getRetCode().equals("0000")){
				StoreBatchDetail storeBatchDetail = (StoreBatchDetail) resDetail.getResMap().get("storeBatchDetail");
				if ("0000".equals(res.getValue("retCode"))) {
					//~~~~~~~~~~~~~~~~~~~~~~~~~更新批次详情（创建店铺成功时）~~~~~~~~~~~~~~~~~~~~~~~~~
					storeBatchDetail.setMerId((String) res.getValue("merId"));//主商户号
					storeBatchDetail.setStoreId((String) res.getValue("storeId"));//店铺号
					storeBatchDetail.setRegisterProcsState("03");//状态
				}else if("0001".equals(res.getValue("retCode"))){
					//~~~~~~~~~~~~~~~~~~~~~~~~~更新批次详情（创建店铺失败时）~~~~~~~~~~~~~~~~~~~~~~~~~
					storeBatchDetail.setFailReason((String) res.getValue("retMsg"));
				}else {
					//~~~~~~~~~~~~~~~~~~~~~~~~~更新批次详情（创建店铺异常时）~~~~~~~~~~~~~~~~~~~~~~~~~
					storeBatchDetail.setFailReason("服务器异常，请稍后再试");//失败原因
				}
				storeBatchDetail.setInTime(null);
				storeBatchDetail.setModTime(null);
				Map<String, Object> map = new HashMap<String, Object>();
				try {
					map = SaasPropertyUtil.javaBeanToMapO(storeBatchDetail);
					reqDetail.putAll(map);
					resDetail = DataEntryUtil.updateBatchDetail(reqDetail);
				} catch (Exception e) {
					logger.error("【更新批次详情】失败", e);
				}
			}
			
		}
		
		//~~~~~~~~~~~~~~~~~~~~~~~~~先查询批次，再更新~~~~~~~~~~~~~~~~~~~~~~~~~
		ReqMessage reqBatch = ReqMessageUtil.makeOpReq();
		ResMessage resBatch = null;
		reqBatch.put("batchNo",batchNo);//批次号
		try {
			resBatch = DataEntryUtil.getStoreBatchByPri(reqBatch);
		} catch (Exception e) {
			logger.error("【根据主键查询批次信息】异常", e);
		}
		if (resBatch.getRetCode().equals("0000")) {
			StoreBatch storeBatch = (StoreBatch) resBatch.getResMap().get("storeBatch");
			//~~~~~~~~~~~~~~~~~~~~~~~~~更新批次~~~~~~~~~~~~~~~~~~~~~~~~~
			if (invalidState > 0) {
				storeBatch.setInvalidDes(invalidInfo);//无效描述
				storeBatch.setInvalidCnt(String.valueOf(invalidState));//无效条数
			}
			storeBatch.setState("0");//状态
			storeBatch.setEndTime(Timestamp.valueOf(DateUtil.getSystemDate("yyyy-MM-dd HH:mm:ss")));//结束时间
			storeBatch.setInTime(null);
			storeBatch.setModTime(null);
			Map<String, Object> map = new HashMap<String, Object>();
			try {
				map = SaasPropertyUtil.javaBeanToMapO(storeBatch);
				reqBatch.putAll(map);
				resBatch = DataEntryUtil.updateBatch(reqBatch);
			} catch (Exception e) {
				logger.error("【更新批次】异常", e);
			}
		}
		
	}
	

	public HSSFSheet getSheet() {
		return sheet;
	}

	public void setSheet(HSSFSheet sheet) {
		this.sheet = sheet;
	}

	public String getBatchNo() {
		return batchNo;
	}

	public void setBatchNo(String batchNo) {
		this.batchNo = batchNo;
	}

	public String getInvalidInfo() {
		return invalidInfo;
	}

	public void setInvalidInfo(String invalidInfo) {
		this.invalidInfo = invalidInfo;
	}

	public int getInvalidState() {
		return invalidState;
	}

	public void setInvalidState(int invalidState) {
		this.invalidState = invalidState;
	}
	
}
 